<?php

namespace App\Admin\Controllers;

use Encore\Admin\Layout\Content;
use Carbon\Carbon;
use App\Models\Collection;
use App\Models\Material;
use App\Models\SeckillProduct;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Controllers\AdminController;
/*use App\Admin\Actions\CollectionAction\MaterialsImages;
use App\Admin\Actions\CollectionAction\MaterialsImagesUpload;*/

class MaterialsController extends AdminController
{
    protected $title = '素材列表';
    
    protected function grid()
    {
        $grid = new Grid(new Material());
         $grid->model()->where('collection_id', request('collection_id'))->orderByDesc('id');
	
	    $grid->disableExport();
	    
	    $grid->column('id', 'ID');
        $grid->column('title', '标题');
        $this->gridActions($grid);
      
        return $grid;
    }
    
    protected function gridActions(Grid $grid)
    {
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableView();
        
        });
    }


    protected function detail($id)
    {
        $show = new Show(Material::findOrFail($id));

        return $show;
    }

    
    protected function form()
    {
        $form = new Form(new Material());
        $form->select('collection_id', '合集选择')->options(Collection::all()->pluck('title', 'id'));
        $form->text('title', '标题');
        $form->radio('is_back', '是否背景图')->options(config('site.bool'))->default(false);
        $form->multipleImage('images', '图片')->removable()->sortable();
        //$this->formSaved($form);

        return $form;
    }

  	/*protected function formSaved(Form $form)
	{
		$form->saved(function () use ($form) {
			dd($form);
			//$product = $this->product($form->model()->id) ?? null;
			//app(MakeProductThumbnail::class, ['product' => $product])->make();
		});
	}*/
  
}
